package com.dotflat.survey.controller;

import com.dotflat.rest.controller.RestfulBaseController;
import com.dotflat.survey.domain.SurveyAnswer;
import com.dotflat.survey.dto.SurveyAnswerDTO;
import com.dotflat.survey.po.SurveyAnswerPO;
import com.dotflat.survey.repository.SurveySheetItemRepository;
import com.dotflat.survey.service.SurveyAnswerItemService;
import com.dotflat.survey.service.SurveyAnswerService;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.matt.foundation.constant.RequestConstant.TICKET;

@RestController
@RequestMapping("/v2/survey/answer")
@Slf4j
@Api(tags = "问卷 - 答题卡")
public class SurveyAnswerController extends RestfulBaseController<SurveyAnswer, SurveyAnswerService, SurveyAnswerPO> {

    @Autowired
    private SurveyAnswerItemService answerItemService;

    @Autowired
    private SurveySheetItemRepository sheetItemRepository;

    @Autowired
    public void setBaseService(SurveyAnswerService service){
        super.setBaseService(service);
    }

    @Override
    @ApiOperation(value = "获取一个对象", response = SurveyAnswer.class)
    @GetMapping()
    public StatusResponse get(@RequestHeader(TICKET) String ticket, String id){
        return super.get(ticket, id);
    }

    @ApiOperation(value = "获取列表", response = SurveyAnswerDTO.class)
    @GetMapping("/list")
    @Override
    public StatusResponse getList(@RequestHeader(TICKET) String ticket, SurveyAnswerPO param, PagerQuery pagerQuery){
        StatusResponse ret = super.getList(ticket, param, pagerQuery);

        Page<SurveyAnswer> page = (Page<SurveyAnswer>) ret.getData();

        Page<SurveyAnswerDTO> newPage = page.map(o-> SurveyAnswerDTO.of(o));

        return StatusResponse.success(newPage);
    }
}
